{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Regression Test Example Using ObservablesTestCase Class"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This demonstrates using the ObservablesTestCase class through cantera that can compare between two version of a model.  It is expected to also compare against experimental data in the future (currently not implemented)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from rmgpy.tools.observablesRegression import ObservablesTestCase\n",
    "from IPython.display import display, Image\n",
    "from rmgpy.species import Species"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set up reactor conditions \n",
    "ethane = Species().from_smiles('CC')\n",
    "argon = Species().from_smiles('[Ar]')\n",
    "methyl = Species().from_smiles('[CH3]')\n",
    "\n",
    "reactor_type_list = ['IdealGasReactor']\n",
    "mol_frac_list = [{ethane: 0.05, argon: 0.95}]\n",
    "Plist = ([3],'atm')\n",
    "Tlist = ([1500,1750,2000],'K')\n",
    "termination_time = ([5e-5],'s')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set the observables that we care about\n",
    "observables = {'species': [ethane, methyl]}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create observables test case and compare the old and new models\n",
    "\n",
    "minimal = ObservablesTestCase(title = 'Ethane Pyrolysis',\n",
    "                              old_dir = 'data/regression/old',\n",
    "                              new_dir = 'data/regression/new',\n",
    "                              observables = observables,\n",
    "                              #ck2cti = False,  # Set to false means we use RMG's internal conversion to Cantera objects\n",
    "                                              # rather than using cantera's ck2cti parser on the chemkin file.\n",
    "                              )\n",
    "\n",
    "minimal.generate_conditions(reactor_type_list = reactor_type_list,\n",
    "                            reaction_time_list = termination_time,\n",
    "                            mol_frac_list = mol_frac_list,\n",
    "                            Tlist = Tlist,\n",
    "                            Plist = Plist)\n",
    "\n",
    "variables_failed = minimal.compare(tol=0.05, plot=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Display the plots for the conditions\n",
    "observable_species = observables['species']\n",
    "for i in range(len(minimal.conditions)):\n",
    "    for j in range(len(observables['species'])):\n",
    "        condition_index = i+1\n",
    "        species_label = observable_species[j].smiles\n",
    "        print('Plotting condition {0} comparison for species {1}'.format(condition_index, species_label))\n",
    "        display(Image(filename=\"condition_{0}_species_{1}.png\".format(condition_index, species_label)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:rmg_env]",
   "language": "python",
   "name": "conda-env-rmg_env-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
